<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="receive_search" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection"></el-table-column>
          <el-table-column label="用户信息" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <span>用户账号：</span>
                <small>{{ scope.row.username || "----" }}</small>
                <br />
                <span>用户昵称：</span>
                <small>{{ scope.row.nickname || "----" }}</small>
                <br />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="申请信息" min-width="220">
            <template slot-scope="scope">
              <div class="user_table">
                <span>申请人姓名：</span>
                <small>{{ scope.row.name || "----" }}</small>
                <br />
                <span>申请人手机：</span>
                <small>{{ scope.row.tel || "----" }}</small>
                <br />
                <span>申请人毕业院校：</span>
                <small>{{ scope.row.school || "----" }}</small>
                <br />
                <span>申请人学历：</span>
                <small>{{ scope.row.education || "----" }}</small>
                <br />
                <span>申请人身份证号：</span>
                <small>{{ scope.row.card || "----" }}</small>
                <br />
                <span>所属区域：</span>
                <small>
                  {{ scope.row.province || "" }}
                  {{ scope.row.city || "" }}
                  {{ scope.row.area || "" }}
                  {{ scope.row.town || "" }}
                </small>
                <br />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="身份证正面" min-width="160">
            <template slot-scope="scope">
              <div v-if="scope.row.card_face && scope.row.card_face != ''">
                <el-image style="width: 150px;" @click="showbigimg(scope.row)" :src="scope.row.card_face" :preview-src-list="showimg"></el-image>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="身份证反面" min-width="160">
            <template slot-scope="scope">
              <div v-if="scope.row.card_bg && scope.row.card_bg != ''">
                <el-image style="width: 150px;" @click="showbigimg(scope.row)" :src="scope.row.card_bg" :preview-src-list="showimg"></el-image>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="审核状态" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <el-tag type="warning" v-if="scope.row.is_check == 0" effect="dark">审核中</el-tag>
                <el-tag type="success" v-if="scope.row.is_check == 1" effect="dark">审核通过</el-tag>
                <el-tag type="danger" v-if="scope.row.is_check == 2" effect="dark">驳回</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="180">
            <template slot-scope="scope">{{ scope.row.remark }}</template>
          </el-table-column>
          <el-table-column label="申请时间" min-width="180">
            <template slot-scope="scope">
              <div class="user_table">
                {{ scope.row.created_time | getTimeFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="delete_apply(scope.row.id)">删除</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="deleteAll_apply">删除</a>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="编辑" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="rider_single" ref="form" label-width="120px">
        <el-form-item label="审核：">
          <el-col :span="14">
            <el-radio-group v-model="rider_single.is_check" :disabled="
                rider_single.is_check == 1 || rider_single.is_check == 2
              ">
              <el-radio label="0">未审核</el-radio>
              <el-radio label="1">已审核</el-radio>
              <el-radio label="2">驳回</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item>
        <el-form-item label="备注：">
          <el-col :span="12">
            <el-input type="textarea" v-model="rider_single.remark"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="editrider(rider_single)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { riderApplySearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      userSearchData: riderApplySearchData,
      showimg: [],
      multipleSelection: [],
      dialogFormVisible: false,
      rider_single: {
        piclink: ""
      },
      current: "",
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},

      showCity: true
    };
  },

  methods: {
    showbigimg (info) {
      this.showimg.push(info.card_face);
      this.showimg.push(info.card_bg);
    },
    delete_apply (id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getPage.del_checklist({ id_str: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    deleteAll_apply (del_id) {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getPage.del_checklist({ id_str: str }).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", "您已经删除了这条信息。", "success");
                this.getNewsAll(this.searchAll);
              } else {
                this.$swal("删除失败！", "出错啦！", "success");
              }
            });
          }
        });
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    onSuccess (pic) {
      this.rider_single.piclink = pic;
    },
    getIs (val, row) {
      var params = {};
      params.id = row.id;
      params.show = val;
      this.editrider(params);
    },

    changeRadio () {
      this.showCity = false;
      setTimeout(() => {
        this.showCity = true;
      }, 500);
    },
    editrider (item) {
      var params = item;
      this.$api.getPage.save_checklist(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
          this.getNewsAll(this.searchAll);
          this.dialogFormVisible = false;
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    editbtn (item) {
      this.rider_single = JSON.parse(JSON.stringify(item));
      this.dialogFormVisible = true;
    },

    receive_search (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getPage.get_checklist(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload () {
      this.getNewsAll(this.searchAll);
    }
  },
  beforeCreate () { },
  created () {
    this.getNewsAll();
  },
  computed: {}
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
